{% macro submitBtn(text, icon, class = '') %}
{% apply spaceless %}
    {% set text = text|default('pim_common.save')|trans|capitalize %}
    <button type="submit" class="AknButton AknButton--apply {{ class }}" title="{{ text }}">
        {{ text }}
    </button>
{% endapply %}
{% endmacro %}

{% macro deleteLinkAttributes(url, redirectUrl, message, successMessage, title, subTitle, errorMessage) %}{% apply spaceless %}
    {% set message = message|default('pim_enrich.entity.fallback.module.delete.item') %}
    {% set title = title|default('confirmation.delete'|trans) %}
    {% set successMessage = successMessage|default('flash.entity.removed'|trans) %}
    {% set errorMessage = errorMessage|default('The element could not be deleted')|trans %}
    href="javascript:void(0);" data-dialog="delete" data-title="{{ title }}" data-subtitle="{{ subTitle }}" data-message="{{ message }}" data-url="{{ url }}" data-redirect-url="{{ redirectUrl }}" data-method="DELETE" data-error-message="{{ errorMessage }}" data-success-message="{{ successMessage }}"
{% endapply %}{% endmacro %}

{% macro deleteLink(url, acl, redirectUrl, message, successMessage, title, class = '', subTitle = '', errorMessage = '') %}{% apply spaceless %}
    {% if acl is null or resource_granted(acl) %}
        {% import _self as elements %}
        <a class="{{ class }}" title="{{ 'pim_common.delete'|trans|capitalize }}" {{elements.deleteLinkAttributes(url, redirectUrl, message, successMessage, title, subTitle, errorMessage)}} >
            {{ 'pim_common.delete'|trans|capitalize }}
        </a>
    {% endif %}
{% endapply %}{% endmacro %}

{% macro link(text, url, opts = {}) %}
{% apply spaceless %}
    {% set title = opts.title is defined ? opts.title : text %}
    {% set icon = opts.icon is defined ? opts.icon : null %}
    <a{% if opts.id is defined %} id="{{ opts.id }}"{% endif %} class="{{ opts.class is defined ? opts.class|join(' ') }}" href="{{ url ? url : 'javascript:void(0);' }}"{% if title %} title="{{ title|trans|capitalize }}"{% endif %}{% if opts.attr is defined %}{% for key, value in opts.attr %} {{ key }}="{{ value }}"{% endfor %}{% endif %}>
        {{ text|trans|capitalize }}
    </a>
{% endapply %}
{% endmacro %}

{% macro page_header(options) %}
    {% set title = options.title is defined ? options.title : '' %}
    {% set buttons = options.buttons is defined ? options.buttons : '' %}
    {% set meta = options.meta is defined ? options.meta : '' %}
    {% set backButton = options.backButton is defined ? options.backButton : '' %}
    {% set state = options.state is defined ? options.state : '' %}
    {% set image = options.image is defined ? options.image : '' %}
    {% set context = options.context is defined ? options.context : '' %}

    <header class="AknTitleContainer navigation">
        <div class="AknTitleContainer-line">
            <div class="AknTitleContainer-imageContainer" data-drop-zone="main-image">{% block image %}{{ image }}{% endblock image %}</div>
            <div class="AknTitleContainer-mainContainer">
                <div>
                    <div class="AknTitleContainer-line">
                        <div class="AknTitleContainer-breadcrumbs" data-drop-zone="breadcrumbs"></div>
                        <div class="AknTitleContainer-buttonsContainer">
                            <div class="AknTitleContainer-userMenuContainer user-menu" data-drop-zone="user-menu"></div>
                            <div class="AknTitleContainer-actionsContainer AknButtonList" data-drop-zone="buttons">{% block navButtons %}{% endblock navButtons %}{% if buttons is not empty %}{{ buttons }}{% endif %}</div>
                        </div>
                    </div>
                    <div class="AknTitleContainer-line">
                        <div class="AknTitleContainer-title" data-drop-zone="title">
                            {% block title %}
                                {{ title }}
                            {% endblock title %}
                        </div>
                        <div class="AknTitleContainer-state" data-drop-zone="state">{{ state }}</div>
                    </div>
                </div>
                <div>
                    <div class="AknTitleContainer-line">
                        <div class="AknTitleContainer-context AknButtonList" data-drop-zone="context">
                            {{ context }}
                        </div>
                    </div>
                    <div class="AknTitleContainer-line">
                        <div class="AknTitleContainer-meta" data-drop-zone="meta">
                            {% block meta %}
                                {{ meta }}
                            {% endblock meta %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="AknTitleContainer-line">
            <div data-drop-zone="navigation"></div>
        </div>
    </header>
{% endmacro %}

{% macro form_navbar(tabs, translationSuffix = '.title') %}
    <div id="form-navbar" class="AknHorizontalNavtab scrollspy-nav">
        <div class="navbar-inner">
            <div class="row-fluid">
                {% if tabs is not empty %}
                    <ul class="AknHorizontalNavtab-list nav nav-tabs">
                        {% if tabs is iterable %}
                            {% for tab in tabs %}
                                <li class="AknHorizontalNavtab-item{% if loop.first %} AknHorizontalNavtab-item--active active{% endif %}">
                                    <a class="AknHorizontalNavtab-link" href="#{{ tab|replace({' ': '-', '.': '-'})|lower }}" data-toggle="tab">{{ (tab ~ translationSuffix)|trans }}</a>
                                </li>
                            {% endfor %}
                        {% else %}
                            <li class="AknHorizontalNavtab-item AknHorizontalNavtab-item--active active"><a href="#{{ tabs|replace({' ': '-', '.': '-'})|lower }}" data-toggle="tab">{{ (tabs ~ translationSuffix)|trans }}</a></li>
                        {% endif %}
                    </ul>
                {% endif %}
            </div>
        </div>
    </div>
{% endmacro %}

{% macro form_errors(form) %}
    {% if form.vars.errors|length %}
        <div class="AknMessageBox AknMessageBox--error fade in top-messages">
            <div class="message">
                {{ form_errors(form) }}
            </div>
        </div>
    {% endif %}
{% endmacro %}

{% macro tabSections(items = {}) %}
    <div class="tabsections">
        {% for title, content in items %}
            {% if content|trim is not empty %}
                <div class="tabsection">
                    <div class="tabsection-title">{{ title|trans }}</div>
                    <div class="tabsection-content">
                        {{ content|raw }}
                    </div>
                </div>
            {% endif %}
        {% endfor %}
    </div>
{% endmacro %}

{% macro updated(formId) %}
{% apply spaceless %}
    <div id="entity-updated" style="opacity: 0">
        <span class="AknState">{{ 'info.updated'|trans }}</span>
    </div>
    <script type="text/javascript" nonce="{{ js_nonce() }}">
        require(
            ['jquery', 'pim/formupdatelistener'],
            function ($, FormUpdateListener) {
                'use strict';
                $(function () {
                    new FormUpdateListener($('#{{ formId }}'));
                });
            }
        );
    </script>
{% endapply %}
{% endmacro %}

{% macro form_container(content) %}
    <div class="AknFormContainer AknFormContainer--withPadding">
        {% autoescape false %}
            {{ content }}
        {% endautoescape %}
    </div>
{% endmacro %}
